<template>
	<view >
	
	<view class="infoTitle">
		填写检测人信息
	</view>
	<view class="infoFill">
	
		<view class="inputContent">
			<input type="text" placeholder="姓名输入" v-model="szDetectVo.szCheckName" />
		</view>
	
		<view class="inputContent">    
			 <uni-forms-item  name="hobby2">
			            <hpy-form-select :dataList="hobbyList" text="text" :hideBorder="true" :title="szDetectVo.szCheckSex===''?'性别选择':szDetectVo.szCheckSex" v-model="szDetectVo.szCheckSex"/>
			</uni-forms-item>
		</view>
		
		<view class="inputContent">
			<input type="number" placeholder="年龄选择" v-model="szDetectVo.szCheckAge" />
		</view>
	
		<view class="inputContent">
			<input type="number" placeholder="联系方式填写（选填）"  v-model="szDetectVo.szCheckTel" />
		</view>
	</view>
	
	
	<view class="confirmIcon" @click="submitInfo()">
		<image  src="https://zhinengjiayi.oss-cn-chengdu.aliyuncs.com/home/login_btn_next_ok%404x.png" ></image>
	</view>
	</view>
</template>

<script>
	import * as HomeApi from '@/api/home/home.js'
	export default{
		data() {
			return {
				// 0表示从首页跳来的表示第一次检测 1表示切换检测人
				flag:null,
				// 这边要给后台传递的数据
				szDetectVo:{
					szCheckName: "",
					szCheckSex: '',
					szCheckAge: '',
					szCheckTel: ''
				},
				hobbyList: [{
				    text: '男',
				}, {
				    text: '女',
				}],
			}
		},
		onLoad(options) {
			const paramsStr = options.params || null; // 获取URL查询参数中的params字段
			if (paramsStr != null) {
				const receivedParams = JSON.parse(paramsStr);
				this.flag=receivedParams.flag;
				
			}
		},
		methods: {	
				async submitInfo(){
				console.log(this.szDetectVo.szCheckSex)
				const szDetectVo=this.szDetectVo
				const phoneNumber = szDetectVo.szCheckTel;
				const reg = /^(\+86)?1[3-9]\d{9}$/; // 匹配+86开头和不带+86的手机号
				if(phoneNumber!=''){
					if (!reg.test(phoneNumber)) {
						// 手机号格式不正确，进行相应处理  
						this.szDetectVo.szCheckTel = '';
						return uni.$showMsg("请输入合法手机号");
					}
				}
				if(szDetectVo.szCheckName===''){
					uni.$showMsg('姓名不能为空')
				} else if(szDetectVo.szCheckAge===''){
					uni.$showMsg('年龄不能为空')
				}else{
				const {
					data:res
				}=await HomeApi.userMessage(this.szDetectVo)
				console.log(res)
				if(res.code===200){
					this.$globalData.isRefresh=true;
					if(this.flag===0){
						
						 uni.redirectTo({
						    url: '/subpkg/AIdiagnos/NewTongueDiagnos/NewTongueDiagnos' 
						  });
						  
					}else if(this.flag===1){
						uni.$goBack();
					}
					
				}
				}
			}
		}
		}
</script>

<style lang="scss">
	.infoTitle{
		margin: 50rpx 0 108rpx 66rpx;
		width: 280rpx;
		height: 50rpx;
		opacity: 1;
		/** 文本1 */
		font-size: 40rpx;
		font-weight: 700;
		letter-spacing: 0rpx;
		line-height: 48.4rpx;
		color: rgba(0, 0, 0, 1);
		text-align: left;
		vertical-align: top;

	}
	.infoFill {
		margin-top: 50rpx;
	
		.inputContent {
			box-sizing: border-box;
			margin-left: 66rpx;
			margin-bottom: 30rpx;
			display: flex;
			align-items: center;
			width: 618rpx;
			height: 88rpx;
			opacity: 1;
			border-radius: 45rpx;
			background: rgba(225, 225, 226, 1.0);

	
			input {
				margin-left: 50rpx;
				width: 60%;
				background: rgba(225, 225, 226, 1.0);
				font-size: 32rpx;
				font-weight: 400;
				letter-spacing: 0rpx;
				line-height: 46.34rpx;
				color: rgba(0, 0, 0, 1);
			}
			.uni-forms-item{
				margin-left: 22px;
				margin-bottom: 0;
				width: 100%;
				.select-picker-arrow-area{
				display: none;	
				}
			}
			
		}
	}
	
	.confirmIcon {
		box-sizing: border-box;
		margin-top: 60rpx;
		margin-left: 554rpx;
	
		text-align: center;
		width: 118rpx;
		height: 118rpx;
		border-radius: 50%;
	
		image {
			width: 100%;
			height: 100%;
			object-fit: cover;
		}
	}
</style>